<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title> <#include "/WEB-INF/content/module-edit.html">
<script type="text/javascript">
var sysStatus = [
      		<#list map["status"] as sysStatus>
      		<#if sysStatus_index!=0>
      		,
      		</#if>
                {"id":"${sysStatus.ecode}","text":"${sysStatus.ename}"}
      		</#list>
      ];
var mode = {
      		<#list map["mode"] as status>
      		<#if status_index!=0>
      		,
      		</#if>
                "${status.ecode}":"${status.ename}"
      		</#list>
      };
var modes = {
      		<#list map["_mode"] as status>
      		<#if status_index!=0>
      		,
      		</#if>
               "${status.ecode}":"${status.ename}"
      		</#list>
};
	$(function() {
		$('#code').validatebox({
			required : true,
			validType : [
					"code",
					'remote["${request.contextPath}/sys/role/validate/code", "code", "${object.code!}"]' ]
		});
		$("#status").combobox({
			valueField : 'id',
			textField : 'text',
  			editable:false,
			data:sysStatus
		});	
	});
	function subButtonFormatter(value, rowData, rowIndex){
		if(rowData.type!="MENU"){
			if(value=="${_id}"){
				var html = "<a href=\"#\" onclick=\"javascript:permission('"
					+ rowData.code
					+ "',false,0);\" style=\"text-decoration:none;border: 1px solid #A8B8D1;background:#eee;\">取消</a>";
				  return html;
			}else{
				return "";	
			}
		}else{
			return "";	
		}
	}
function modeFormatter(value, rowData, rowIndex){
	if(value&&value!="")
		return eval("mode."+value);
		else
			return ""; 	
	}
function modesFormatter(value,rowData,rowIndex){
	if(rowData.type!="MENU"){
	 	if(value&&value!="")
			return "<div style=\"text-align: center;\">" +eval("modes."+value) + "</div>";
		else{
			var html = "&nbsp;&nbsp;<a href=\"#\" onclick=\"javascript:permission('"
				+ rowData.code
				+ "',true,1);\" style=\"text-decoration:none;border: 1px solid #A8B8D1;background:#eee;\">允许</a>";
		
				html += "&nbsp;&nbsp;<a href=\"#\" onclick=\"javascript:permission('"
				+ rowData.code
				+ "',true,2);\" style=\"text-decoration:none;border: 1px solid #A8B8D1;background:#eee;\">禁止</a>&nbsp;&nbsp;";
				return html;
		}
 	}else{
		return "";	
	}
}
	function permission(_module,_permission,_type){
		$.post("permissions",{"_module":_module,"_permission":_permission,"_type":_type},function(data){
			var msg = "保存失败";
			if (data.state) {
				msg = "保存成功";
				top.showMsg(msg);
				$("#sub").treegrid("reload");
			} else {
				top.showMsg(msg);
			}
		});
	}
	
</script>
<style type="text/css">
label {
	cursor: pointer;
}

input[type=checkbox] {
	cursor: pointer;
	border: none;
}
</style>
</head>
<body class="easyui-layout">
	<div region="north"
		style="background-color: #eee; padding: 5px; overflow: hidden;"
		border="false">
		<#if object.code?exists&&object.code!=""> <@auth
		code="sys:role:update"><a href="#" class="easyui-linkbutton"
			plain="true" iconCls="icon-add" style="border: 1px solid #ccc"
			onclick="javascript:save()">保存</a></@auth> <#else> <@auth
		code="sys:role:create"><a href="#" class="easyui-linkbutton"
			plain="true" iconCls="icon-add" style="border: 1px solid #ccc"
			onclick="javascript:save()">保存</a></@auth> </#if><a href="#"
			class="easyui-linkbutton" plain="true" iconCls="icon-edit"
			style="border: 1px solid #ccc" onclick="javascript:cancel()">关闭</a>
	</div>
	<div region="center">
		<div id="p" class="easyui-panel"
			style="background: #fafafa; padding: 10px;" fit="true"
			toolbar="#toolbar">
			<form id="form" method="post">
				<table class="form" cellspacing="0" style="width: 100%">
					<tbody style="border: 1px solid #ccc">
						<tr style="display: none;">
							<td colspan="6"><input id="_id" value="${object.code!}"></td>
						</tr>
						<tr>
							<td class="label">编码：</td>
							<td><#if object.code?exists&&object.code!=""> <#assign
								readonly="readonly=\"readonly\""> </#if> <input id="code"
								name="code" value="${object.code!}"
								${readonly!}   />
							</td>
							<td class="validate">*</td>
							<td class="label">名称：</td>
							<td><input id="name" name="name" value="${object.name!}"
								class="easyui-validatebox" required="required" /></td>
							<td class="validate">*</td>
						</tr>

						<tr>
							<td class="label">别名：</td>
							<td><input id="alias" name="alias" value="${object.alias!}" /></td>
							<td class="validate"></td>
							<td class="label">状态：</td>
							<td><input id="status" name="status"
								value="${object.status!}" required="required" /></td>
							<td class="validate">*</td>

						</tr>
						<tr>
							<td class="label">创建时间：</td>
							<td colspan="4">${object.create_time!}</td>
							<td class="validate"></td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
	<@auth code="sys:role:*:sub"> <#if _id??&&_id!="">
	<div region="south" id="south_div"
		style="background-color: #eee; padding: 5px; overflow: hidden; height: 320px;"
		border="false">
		<table id="sub" class="easyui-treegrid" url="sub" idField="code" treeField="name"
			rownumbers="true" striped="true" fitColumns="true" fit="true"
			singleSelect="true" pagination="false">
			<thead>
				<tr>
					<th field="code" width="50">[功能/模块]编码</th>
					<th field="name" width="100">[功能/模块]名称</th>
					<th field="auth" width="50">权限码</th>
					<th field="parent" width="30">所属菜单编码</th>
<!-- 				<th field="parentName" width="30">所属菜单名称</th>  -->
					<th field="mode" width="20" formatter="modeFormatter">许可方式</th><@auth
					code="sys:role:*:permissions">
					<th field="m_mode" formatter="modesFormatter" width="30">授权方式</th>
					<th field="permission_role" width="10"
						formatter="subButtonFormatter" align="center">操作</th></@auth>
				</tr>
			</thead>
		</table>
	</div>
	</#if> </@auth>
</body>
</html>